<%--
  Created by IntelliJ IDEA.
  User: Administrator  查看模板问卷
  Date: 2016/10/8
  Time: 14:56
  To change this template use File | Settings | File Templates.
--%>
<%@ page language="java" import="java.util.*" pageEncoding="utf-8" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%
  String path = request.getContextPath();
  String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";
%>
<html>
<head>
  <base href="<%=basePath%>">
  <meta charset="utf-8"/>
  <title></title>
  <link rel="stylesheet" type="text/css" href="easyui-1.3.6/themes/default/easyui.css">
  <link rel="stylesheet" type="text/css" href="easyui-1.3.6/themes/icon.css">
  <link rel="stylesheet" type="text/css" href="easyui-1.3.6/demo/demo.css">
  <script type="text/javascript" src="easyui-1.3.6/jquery.min.js"></script>
  <script type="text/javascript" src="easyui-1.3.6/jquery.easyui.min.js"></script>

  <script type="text/javascript">
    function rowformater(value,row,index)
    {
//      rest/page/selectTemplateParticulars
      return "<a href='rest/page/selectTemplateParticulars?templateId="+row.templateId+"&templateTitle="+encodeURIComponent(row.templateTitle)+"&questionnaireExplain="+encodeURIComponent(row.questionnaireExplain)+"&publishObjects="+encodeURIComponent(row.publishObjects)+"' target='_blank'>操作</a>";
    }
//    "&templateTitle"+row.templateTitle+"&questionnaireExplain"+row.questionnaireExplain+"&publishObjects"+row.publishObjects+
  </script>

</head>
<body>
<div class="row">
  <div class="col-md-12">
    <!-- BEGIN PAGE TITLE & BREADCRUMB-->
    <h3 class="page-title" id="index-page-title" style="font: normal 30px/0.8em '微软雅黑'">孜点教科</h3>
    <ul class="page-breadcrumb breadcrumb">
     <%-- <li>
        <i class="fa fa-home"></i>
        首页
        <i class="fa fa-angle-right"></i>
      </li>--%>
      <li>
        <%--<a href="javascript:;">--%>
       问卷管理
        <%--</a>--%>
        <i class="fa fa-angle-right"></i>
      </li>
      <li>
        <%--<a href="javascript:;">--%>
        查看问卷模板
        <%--</a>--%>
      </li>
    </ul>
    <!-- END PAGE TITLE & BREADCRUMB-->
  </div>
</div>

<input class="easyui-searchbox" data-options="prompt:'请输入问卷模板的标题查询',searcher:doSearch" style="width:450px;height: 48px;background: transparent;border:none;">

<div style="margin:20px 0;"></div>
<div id="test" class="easyui-dialog" data-options="closed:true,modal:true,title:'是否要删除当前所选择的模板'" style="width: 400px;">
  <div style="width:368px;height:160px;margin:auto;" >
     <a href="javascript:void(0)" class="easyui-linkbutton" onclick="delStudent()" style="display:inline-block;width:120px;height:30px;margin:65px 0px 0px 122px;line-height:30px;">确认删除当前模板</a>
  </div>
</div>
<table id="dg" title="问卷模板信息表" style="width:auto;height:auto" data-options="
				rownumbers:true,
				singleSelect:true,
				autoRowHeight:false,
				pagination:true,
				pageSize:10
				">
  <thead>
  <tr>
    <th field="templateId" >问卷模板编号</th>
    <th field="templateTitle" >模板问卷标题</th>
    <th field="questionnaireExplain">模板问卷说明</th>
    <th field="publishObjects" >问卷面向群体</th>
    <th data-options="field:'id',formatter:  rowformater">操作</th>
  </tr>
  </thead>
</table>

<script>
  var i = 1;
  function pagerFilter(data){
    if(i==1&&data[0]!=null){
      var to = data[0].total;
      var wh = data[0].wh;
    }else if(i==2&&data!=null){
      var to = data.total;
      var wh = data.wh;
    }else{
      var to = 0;
      var wh = "";
    }
    if (typeof to== 'number' && typeof data.splice == 'function'){	// is array
      data = {
        total:to,
        rows: data,
        wh:wh
      }
      i=2;
    }
    var dg = $(this);
    var opts = dg.datagrid('options');
    var pager = dg.datagrid('getPager');
    pager.pagination({
      onSelectPage:function(pageNum, pageSize){
        opts.pageNumber = pageNum;
        opts.pageSize = pageSize;
        pager.pagination('refresh',{
          pageNumber:pageNum,
          pageSize:pageSize
        });
        var start = (opts.pageNumber-1)*parseInt(opts.pageSize);
//    var end = start + parseInt(opts.pageSize);
        data.rows = (getData(start,parseInt(opts.pageSize),wh));
        dg.datagrid('loadData',data);
      }
    });
    return data;
  }

  $(function(){
    $('#dg').datagrid({
      toolbar:[
        {
          text:'删除所选中的一条信息',
          iconCls:'icon-remove',
          handler:function(){
            $('#test').window('open');
          }
        }
      ]})

    $('#dg').datagrid({loadFilter:pagerFilter}).datagrid('loadData', getData(0,10,""));
  });
  function delStudent(){
    var row = $('#dg').datagrid('getSelected');
    if (delData(row.templateId)==200){
      var index = $('#dg').datagrid('getRowIndex', row);
      $('#test').window('close');
      $('#dg').datagrid('deleteRow', index);
    }else{
      alert("删除失败")
    }
  }
  function delData(s){
    var code1 = 0;
    $.ajax({
      method : 'GET',
      url : 'rest/QuestionnaireTemplate/delTemplate?manageId=${user.teacherid}&templateId='+s+'',
      async : false,
      dataType : 'json',
      success : function(code) {
        code1 = code.code
        if(code.code == 200){
          $.messager.show({title:'操作提示',msg:code.message+"请点击表单下刷新按钮刷新显示",showType:'show',style: {
            top:($(window).height()-200) * 0.5,
            left:($(window).width() -250) * 0.5
          }});
        }else{
          $.messager.show({title:'操作提示',msg:code.message,showType:'show',style: {
            top:($(window).height()-200) * 0.5,
            left:($(window).width() -250) * 0.5
          }});
        }
      },
      error : function() {
        alert('error!!!');
      }
    });
    return code1
  }

  function getData(r,p,s){
    var infor_data = [];
    var total = 0;
    $.ajax({
      method : 'post',
      url : 'rest/QuestionnaireTemplate/vagueSelectTemplate',
      data:'startrow='+r+'&pageSize='+p+'&templateTitle='+s+'&manageId=${user.teacherid}',
      async : false,
      dataType : 'json',
      success : function(data) {
        infor_data = data.data
        total = data.total
//        alert("什么东西："+infor_data)
      },

      error : function() {
        alert('error!!');
      }

    });
    var rows = [];

    if(infor_data!=null) {
//      alert(infor_data.length)
      for (var i = 0; i < infor_data.length; i++) {
        rows.push({
          total: total,
          wh: s,
          templateId: infor_data[i].templateId,
          templateTitle: infor_data[i].templateTitle,
          questionnaireExplain: infor_data[i].questionnaireExplain,
          publishObjects: infor_data[i].publishObjects
        });
      }
    }else{
      alert("返回为空")
    }
    return rows;
  }

  function doSearch(value){
    i = 1;
    $('#dg').datagrid({loadFilter:pagerFilter}).datagrid('loadData', getData(0,10,value));
  }



</script>
</body>
</html>
